layui.config({
	base : "js/"
}).use(['form','layer','jquery','laypage','laydate','layedit'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
        laydate = layui.laydate,
        layedit = layui.layedit,
       
		$ = layui.jquery;
         var start = {
            // min: laydate.now()
            min:  '2000-06-16 23:59:59'
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };

        var end = {
            min: '2000-06-16 23:59:59'
            ,max: '2099-06-16 23:59:59'
            ,istoday: false
            ,choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };

        document.getElementById('LAY_demorange_s').onclick = function(){
            start.elem = this;
            laydate(start);
        }
        document.getElementById('LAY_demorange_e').onclick = function(){
            end.elem = this
            laydate(end);
        }

           // editIndex = layedit.build('demo')

	form.on("submit(workStore)",function(data){
         // layedit.sync(editIndex);
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        $.ajax({
            type:'post',
            url:'/staff/store/work',
            async:false,
            data:{
                '_token':$('input[name=_token]').val(),
                'room_id':$('input[name=user]').attr('key'),  
                 'user':$('input[name=user]').val(),
                 'user_phone':$('input[name=user_phone]').val(),
                 'clerk':$('input[name=derk]').val(),
                 'clerk_phone':$('input[name=derk_phone]').val(),
                 'start_time':$('input[name=ftime]').val(),
                 'end_time':$('input[name=ltime]').val(),
                 'details':$('#demo').val()
            },
            dataType:'json',
            success:function (data) {
                console.log(data)
                if(data.status == 1){
                    top.layer.close(index);
                    top.layer.msg("工单编辑成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.close(index);
                    top.layer.msg("工单编辑失败！");
                }
            }
        })
        return false;
    })
});

